package cn.gson.oasys.task;

import cn.gson.oasys.services.mail.MailServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时发送邮件任务类
 */
@Component
public class SendMailTask {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private MailServices mailServices;

    // 发件人账号
    public static final String ACCOUNT = "3162245874@qq.com";

    // 发件人密码
    public static final String PASSWORD = "rgvddzzucqddddhd";

    // 接收人邮箱号
    public static final String RECEIVER = "shenao31622@163.com";

    // 发件人昵称
    public static final String NAME = "奥利奥";

    // 邮件主题
    public static final String TITLE = "定时任务测试邮件";

    // 邮件内容
    public static final String CONTENT = "hello shenao";

    /**
     * 每分钟发送一次邮件
     */
    @Scheduled(cron = "0 0 * * * *")
    public void sendMail() {
        System.out.println("定时器当前执行时间：" + sdf.format(new Date()));

        // 使用授权码不需要解析密码

        mailServices.pushmail(ACCOUNT, PASSWORD, RECEIVER, NAME, TITLE, CONTENT, null, null);
    }
}
